package com.controller;

import com.entity.*;
import com.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @ClassName IndexController
 * @Description 首页控制层
 */
@Controller
public class IndexController extends BaseController {

    @Autowired
    private BanciService banciService;
    @Autowired
    private DxService dxService;
    @Autowired
    private FangshiService fangshiService;
    @Autowired
    private GaiqianshenqingService gaiqianshenqingService;
    @Autowired
    private GonggaoService gonggaoService;
    @Autowired
    private LeibieService leibieService;
    @Autowired
    private LianjieService lianjieService;
    @Autowired
    private LiuyanService liuyanService;
    @Autowired
    private LunboService lunboService;
    @Autowired
    private TuipiaoshenqingService tuipiaoshenqingService;
    @Autowired
    private UsersService usersService;
    @Autowired
    private YudingService yudingService;
    @Autowired
    private ZixunService zixunService;
    @Autowired
    private ZuoweiService zuoweiService;


    //首页
    @RequestMapping("/index")
    public ModelAndView index(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("index");
        //取出所有业务表数据存储到session里方便前端页面随意调用
        HttpSession session = request.getSession();

        //班次表banci
        List<Banci> banciList = banciService.findAll();
        session.setAttribute("banciList", banciList);
        session.setAttribute("banciListSize", banciList.size());
        //介绍表dx
        List<Dx> dxList = dxService.findAll();
        session.setAttribute("dxList", dxList);
        session.setAttribute("dxListSize", dxList.size());
        //支付方式表fangshi
        List<Fangshi> fangshiList = fangshiService.findAll();
        session.setAttribute("fangshiList", fangshiList);
        session.setAttribute("fangshiListSize", fangshiList.size());
        //改签申请表gaiqianshenqing
        List<Gaiqianshenqing> gaiqianshenqingList = gaiqianshenqingService.findAll();
        session.setAttribute("gaiqianshenqingList", gaiqianshenqingList);
        session.setAttribute("gaiqianshenqingListSize", gaiqianshenqingList.size());
        //票务公告表gonggao
        List<Gonggao> gonggaoList = gonggaoService.findAll();
        session.setAttribute("gonggaoList", gonggaoList);
        session.setAttribute("gonggaoListSize", gonggaoList.size());
        //类别表leibie
        List<Leibie> leibieList = leibieService.findAll();
        session.setAttribute("leibieList", leibieList);
        session.setAttribute("leibieListSize", leibieList.size());
        //友情链接表lianjie
        List<Lianjie> lianjieList = lianjieService.findAll();
        session.setAttribute("lianjieList", lianjieList);
        session.setAttribute("lianjieListSize", lianjieList.size());
        //留言反馈表liuyan
        List<Liuyan> liuyanList = liuyanService.findAll();
        session.setAttribute("liuyanList", liuyanList);
        session.setAttribute("liuyanListSize", liuyanList.size());
        //轮播图表lunbo
        List<Lunbo> lunboList = lunboService.findAll();
        session.setAttribute("lunboList", lunboList);
        session.setAttribute("lunboListSize", lunboList.size());
        //退票申请表tuipiaoshenqing
        List<Tuipiaoshenqing> tuipiaoshenqingList = tuipiaoshenqingService.findAll();
        session.setAttribute("tuipiaoshenqingList", tuipiaoshenqingList);
        session.setAttribute("tuipiaoshenqingListSize", tuipiaoshenqingList.size());
        //用户表users
        List<Users> usersList = usersService.findAll();
        session.setAttribute("usersList", usersList);
        session.setAttribute("usersListSize", usersList.size());
        //预定表yuding
        List<Yuding> yudingList = yudingService.findAll();
        session.setAttribute("yudingList", yudingList);
        session.setAttribute("yudingListSize", yudingList.size());
        //新闻资讯表zixun
        List<Zixun> zixunList = zixunService.findAll();
        session.setAttribute("zixunList", zixunList);
        session.setAttribute("zixunListSize", zixunList.size());
        //座位表zuowei
        List<Zuowei> zuoweiList = zuoweiService.findAll();
        session.setAttribute("zuoweiList", zuoweiList);
        session.setAttribute("zuoweiListSize", zuoweiList.size());

        return mav;
    }
}
